package com.klanpaia.basicGame;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.Align;
import com.klanpaia.basicGame.ScreenGame;

public class MainMenu implements Screen{
	 MeuGame game;
	 Stage stage;
	 BitmapFont black;
	 BitmapFont white;
	 SpriteBatch batch;
	 Skin skin;
	 TextureAtlas atlas;
	 TextButton button;
	 Label label;
	
	public MainMenu(MeuGame game) {
		super();
		this.game = game;
	}

	@Override
	public void render(float delta) {
	Gdx.gl.glClearColor(0, 0, 0, 1);
	Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
	
	stage.act(delta);
		batch.begin();
		
		stage.draw();

		batch.end();
	}

	
	@Override
	public void resize(int width, int height) {
	if(stage == null){
		stage = new Stage(width, height, true);
	}
	stage.clear();
	
	Gdx.input.setInputProcessor(stage);
	
	TextButtonStyle style = new TextButtonStyle(); 	
	style.up =  skin.getDrawable("1");
	style.down =  skin.getDrawable("1");
	
	style.font = black;
	
	button = new TextButton("Pressione Me", style);
	button.setWidth(400);
	button.setHeight(100);
	button.setX(Gdx.graphics.getWidth() / 2 - button.getWidth() / 2);
	button.setY(Gdx.graphics.getWidth() /2 - button.getWidth() / 2);
	
	button.addListener(new InputListener(){
		
		public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
			
			return true;
		}
		
		
		public void touchUp(InputEvent event, float x, float y, int pointer, int button){
			game.setScreen(new ScreenGame(game));
		}
	});
	
	LabelStyle lb = new LabelStyle(black, Color.WHITE);
	label = new Label("Meu primeiro game", lb);
	label.setX(0);
	label.setY(Gdx.graphics.getHeight() / 2 + 100);
	label.setWidth(width);
	label.setAlignment(Align.center);
	
	stage.addActor(button);
	stage.addActor(label);
	
	}

	@Override
	public void show() {
	
		batch = new SpriteBatch();
		skin = new Skin();
		atlas = new TextureAtlas("data/button.atlas");
		skin.addRegions(atlas);
		black = new BitmapFont(Gdx.files.internal("data/whitefont.fnt"), false);
		
		
		
	}

	@Override
	public void hide() {
	
		
	}

	@Override
	public void pause() {
	
		
	}

	@Override
	public void resume() {
	
		
	}

	@Override
	public void dispose() {
	
		
	}

}
